<template>
    <v-card>
        <v-card-title primary-title class="green darken white--text">
            <h3 class="headline mb-0 white--text">注册</h3>
        </v-card-title>
        <v-card-text class="pl-4 pr-4">
            <form>
                <v-text-field
                    label="邮箱地址"
                    v-model="email"
                    :error-messages="errors.collect('email')"
                    v-validate="'required|email'"
                    data-vv-name="email"
                    type="text"
                    required
                ></v-text-field>
                <v-text-field
                    label="输入密码"
                    v-model="password"
                    v-validate="'required|max:30|min:6'"
                    :error-messages="errors.collect('password')"
                    data-vv-name="password"
                    type="password"
                    :counter="30"
                    required
                ></v-text-field>
                <v-text-field
                    label="再次输入密码"
                    v-model="password1"
                    v-validate="'required|max:30|min:6'"
                    :error-messages="errors.collect('password')"
                    data-vv-name="password1"
                    type="password"
                    :counter="30"
                    required
                ></v-text-field>
                <v-layout justify-space-between>
                    <v-btn @click="submit" class="green lighten-1 ma-0">注册</v-btn>
                    <v-btn @click="clear" class="ma-0">登陆</v-btn>
                </v-layout>
            </form>
        </v-card-text>
    </v-card>
</template>

<script>
  import axios from 'axios'
  import qs from 'qs'
  export default {
    layout: 'center',
    name: 'Login',
    data: () => ({
      email: 'aaa@aaa.com',
      password: '123456',
      password1: '123456'
    }),
    methods: {
      submit () {
        //        this.$validator.validateAll()
        //        axios.get('http://zhiliao.com/user/register')
        //          .then(function (response) {
        //            console.log(response.data)
        //            history.forward('/user/login')
        //          })
        //          .catch(function (error) {
        //            console.log(error)
        //          })
        //        if (this.$refs.loginForm.validate()) {
        axios.post('/webapi/user/register', qs.stringify({
          email: this.email,
          password: this.password,
          password1: this.password1
          // _token: parent.$refs.token.content
        }), {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then(response => {
          //          console.log(response.data)
          if (response.data.code === 0) {
            this.content.router.push({path: '/webapi/user/login'})
          }
        }).catch(function (error) {
          console.log(error)
          alert(11)
        })
      },
      clear () {
        this.email = ''
        this.password = ''
        this.remember_pwd = null
        this.$validator.clean()
      }
    }
  }
</script>